package role

import (
	"context"
	"time"

	"go-weixin/app/usercenter/api/internal/svc"
	"go-weixin/app/usercenter/api/internal/types"
	"go-weixin/app/usercenter/rpc/pb/proto/usercenter"

	"github.com/zeromicro/go-zero/core/logx"
)

type RoleUpdatePowerLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRoleUpdatePowerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RoleUpdatePowerLogic {
	return &RoleUpdatePowerLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RoleUpdatePowerLogic) RoleUpdatePower(req *types.RoleUpdatePowerReq) (resp *types.RoleUpdatePowerResp, err error) {
	ctx, cannFunc := context.WithTimeout(context.Background(), 5*time.Second)
	defer cannFunc()
	_, err = l.svcCtx.UserRpc.RoleUpdatePower(ctx, &usercenter.RoleUpdatePowerReq{
		RoleId:     req.RoleId,
		OldPowerId: req.OldPowerId,
		NewPowerId: req.NewPowerId,
	})
	return
}
